<extend name="Public:base" />

<block name="additional-styles">
	<!-- DataTables -->
	<link rel="stylesheet" href="__PUBLIC__/Admin/plugins/datatables/dataTables.bootstrap.css" />
</block>

<block name="content-wrapper">
	<!-- Content Wrapper. Contains page content -->
	<div class="content-wrapper">
		<!-- Content Header (Page header) -->
		<section class="content-header">
			<h1>
				作业提交情况
				<small>Homework Submission</small>
			</h1>
			<ol class="breadcrumb">
				<li>
					<a href="{:U('Index/index')}"> <i class="fa fa-dashboard"></i>
						首页
					</a>
				</li>
				<li class="active">作业提交情况</li>
			</ol>
		</section>

		<!-- Main content -->
		<section class="content">
			<div class="row">
				<div class="col-xs-12">
					<div class="box">
						<div class="box-header">
							<!-- <h3 class="box-title">Data Table With Full Features</h3>-->
							<div class="row">
								<form id="form-index" class="form-horizontal" action="{:U('HomeworkStudent/index')}" method="post">
									<div class="col-xs-4">
										<div class="form-group">
											<label class="col-sm-3 control-label">逻辑班级</label>
											<div class="col-sm-9">
												<select id="logic_class_id" class="form-control">
													<volist name="logic_classes" id="vo">
														<eq name="vo.id" value="$logic_class_id">
															<option value="{$vo.id}" selected="selected">{$vo.name}</option>
														<else />
															<option value="{$vo.id}">{$vo.name}</option>
														</eq>
													</volist>											
								                </select>
											</div>
										</div>										
									</div>
									<div class="col-xs-4">
										<div class="form-group">
											<label class="col-sm-3 control-label">作业题目</label>
											<div class="col-sm-9">
												<select name="homework_id" id="homework_id" class="form-control">
													<volist name="homeworks" id="vo">
														<eq name="vo.id" value="$homework_id">
															<option value="{$vo.id}" selected="selected">{$vo.title}</option>
														<else />
															<option value="{$vo.id}">{$vo.title}</option>
														</eq>
													</volist>											
								                </select>
											</div>
										</div>										
									</div>
								</form>
							</div>
						</div>
						<!-- /.box-header -->
						<div class="box-body">
							<table id="example1" class="table table-bordered table-striped">
								<thead>
									<tr>
										<th>学号</th>
										<th>姓名</th>
										<th>所在班级</th>
										<th>提交情况</th>
										<th>得分</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody>
									<volist name="students" id="vo">
										<tr>
											<td>{$vo.id}</td>
											<td>{$vo.name}</td>
											<php>
												$major_id = $vo['class']['major_id'];
												$major = get_major_by_id($major_id);
												$academy_id = $major['academy_id'];
												$academy = get_academy_by_id($academy_id);
											</php>
											<td>{$academy.name}---{$vo.class.grade}级---{$major.name}---{$vo.class.class}班</td>
											<php>
												$submit_result = '';
												switch(is_homework_submitted($homework_id, $vo['id'])) {
													case 0:
														$submit_result = '未提交';
														break;
													case 1:
														$submit_result = '超时提交';
														break;
													case 2:
														$submit_result = '准时提交';
														break;
												}
											</php>
											<td>{$submit_result}</td>
											<php>
												$score = is_homework_scored($homework_id, $vo['id']);
												$score = false === $score? '未打分' : $score;
											</php>
											<td>{$score}</td>
											<td>
												<eq name="submit_result" value="未提交">
													<a class="btn btn-default btn-sm" disabled="disabled">下载查阅</a>
													<a class="btn btn-default btn-sm" disabled="disabled">在线查阅</a>											
													<button class="btn btn-default btn-sm" data-toggle="modal" data-target="#modal-score" data-whatever="{$vo.id}" disabled="disabled">打分</button>
												<else />
													<a href="{:U('HomeworkStudent/download', array('homework_id' => $homework_id, 'student_id' => $vo['id']))}" class="btn btn-default btn-sm">下载查阅</a>											
													<a href="{:U('HomeworkStudent/view', array('homework_id' => $homework_id, 'student_id' => $vo['id']))}" target="_blank" class="btn btn-default btn-sm">在线查阅</a>											
													<button class="btn btn-default btn-sm" data-toggle="modal" data-target="#modal-score" data-whatever="{$vo.id}">打分</button>
												</eq>
											</td>
										</tr>
									</volist>
								</tbody>
								<tfoot>
									<tr>
										<th>学号</th>
										<th>姓名</th>
										<th>所在班级</th>
										<th>提交情况</th>
										<th>得分</th>
										<th>操作</th>
									</tr>
								</tfoot>
							</table>
						</div>
						<!-- /.box-body -->
					</div>
					<!-- /.box -->
				</div>
			</div>
		</section>
		<!-- /.content -->
	</div>
	<!-- /.content-wrapper -->
	<!-- 打分 模态框 -->
	<div class="modal" id="modal-score">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">×</span>
					</button>
					<h4 class="modal-title">打分</h4>
				</div>
				<div class="modal-body">
					<div class="container-fluid">
						<div class="row">
							<form id="form-score" class="form-horizontal" action="{:U('HomeworkStudent/score')}" method="post">
								<div class="form-group">
									<label class="col-sm-2 control-label">分数</label>
									<div class="col-sm-9">
										<input name="homework_id" id="homework_id_modal" type="hidden">
										<input name="student_id" id="student_id_modal" type="hidden">
										<input name="score" id="score_modal" type="number" class="form-control">
									</div>
								</div>
							</form>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<button id="button-score-submit"type="button" class="btn btn-primary">确定</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<!-- /.modal -->
</block>

<block name="additional-scripts">
	<!-- DataTables -->
	<script src="__PUBLIC__/Admin/plugins/datatables/jquery.dataTables.min.js"></script>
	<script src="__PUBLIC__/Admin/plugins/datatables/dataTables.bootstrap.min.js"></script>
	<script>
		$(function () {
			$("#example1").DataTable();
			$('#example2').DataTable({
				"paging": true,
				"lengthChange": false,
				"searching": false,
				"ordering": true,
				"info": true,
				"autoWidth": false
			});

			// 逻辑班级和作业题目二级联动
			$('#logic_class_id').change(function() {
				var logic_class_id = $('#logic_class_id').val();
				$.post('__MODULE__/HomeworkStudent/getHomeworksByLogicClassId',
				{
					logic_class_id: logic_class_id
				},
				function(data, status) {
					$('#homework_id').empty();
					var homeworks = data;
					for(var key in homeworks) {
						$('#homework_id').append('<option value="' + homeworks[key]['id'] + '">' + homeworks[key]['title'] + '</option>');
					}
					$('#homework_id').change();
				});	
			});
			// 提交form-index表单
			$('#homework_id').change(function() {
				$('#form-index').submit();
			});

			// 打分
			$('#modal-score').on('show.bs.modal', function(event) {
				var button = $(event.relatedTarget);
				var student_id = button.data('whatever');	
				var homework_id = $('#homework_id').val();
				$('#homework_id_modal').val(homework_id);
				$('#student_id_modal').val(student_id);
			});
			// 提交打分表单
			$('#button-score-submit').click(function() {
				$('#form-score').submit();
			});
		});
	</script>
</block>